﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YJTTool.Common.Enums;

namespace YJTTool.Common.Events
{
    public class MethodEvent
    {
        private static MethodEvent _instance;

        // 私有构造函数，防止外部直接实例化
        private MethodEvent() { }

        public static MethodEvent Instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new MethodEvent();
                }
                return _instance;
            }
        }
        public delegate void MethodEventHandler(string v);

        public event MethodEventHandler OnMessageReceived;

        public void PushMessage(string message)
        {
            OnMessageReceived?.Invoke(message); // 触发事件
        }
        public void Subscribe(MethodEventHandler handler)
        {
            OnMessageReceived += handler;
        }

        public void Unsubscribe(MethodEventHandler handler)
        {
            OnMessageReceived -= handler;
        }
    }

}
